package com.rfsp.mcp.service;

import com.rfsp.common.base.BaseService;
import com.rfsp.common.service.AreaService;
import com.rfsp.common.mapper.OrgMapper;
import com.rfsp.common.pojo.po.OrgPO;
import com.rfsp.common.service.DictService;
import com.rfsp.mcp.pojo.vo.BankVO;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BankService extends BaseService<OrgPO> {

	@Autowired
	OrgMapper orgMapper;

	@Autowired
	AreaService areaCodeService;

	@Autowired
    DictService dictService;

	@Autowired
	OrgTypeService orgTypeService;

	public BankVO getById(Long id){
		if(id==null){
			return null;
		}
		OrgPO org=orgMapper.selectByPrimaryKey(id);
		BankVO vo=new BankVO();
		BeanUtils.copyProperties(org,vo);
		return vo;
	}
	public void combo(BankVO vo){
		vo.setOrgTypeName(orgTypeService.getTypeName(vo.getOrgType()));
		vo.setEnterpriseScaleName(dictService.getDictName("DD_107",vo.getEnterpriseScale()));
		vo.setEnterpriseTypeName(dictService.getDictName("DD_112",vo.getEnterpriseType()));
		vo.setIndustryName(dictService.getDictName("DD_109",vo.getIndustry()));
		vo.setCurrencyName(dictService.getDictName("DD_106",vo.getCurrency()));
		
		String areaCode = StringUtils.isNotBlank(vo.getCounty())?vo.getCounty():(StringUtils.isNotBlank(vo.getCity())?vo.getCity():vo.getProvince());
		vo.setAreaName(areaCodeService.getFullAddress(areaCode).replace("-", ""));
    }
    public void combo(List<BankVO> voList){
        for(BankVO vo:voList ){
            combo(vo);
        }
    }
}
